<template>
	<view>
		<view class="login-bg">
			<image src="../../static/image/lp1.jpg" style="background-size: 100% 100%;" mode=""></image>
			<view class="login-head">
				<image src="../../static/image/head.png"></image>
				<view class="login-text">
					第六感
				</view>
			</view>
			<view class="login-body" open-type="getUserInfo" @click="getUser">
				微信授权登陆
			</view>
			<view class="login-rideo">
				<view class="radio">
					<radio color="#202020" />
					<view>
						<view>
							我已阅读且同意
						</view>
						<view class="gred">《隐私条款》《用户协议》</view>
					</view>
				</view >
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			}
		},
		methods: {
			getUser(e) {
				wx.getUserProfile({
					desc: '用户完善会员资料',
					success: res => {
						let userInfo = res.userInfo;
						uni.showLoading({
							title:'登录中'
						});
						wx.login({
							//成功放回
							success: (res) => {
								let code = res.code
								console.log(res)
								wx.request({
									url: `https://api.weixin.qq.com/sns/jscode2session?appid=wxb104bc1a12b9d850&
									secret=d773510a932de0499b46be6a40ecc2e6&js_code=${code}&grant_type=authorization_code`,
									success: (res) => {
										userInfo.openid = res.data.openid
										//存储用户信息
										wx.setStorage({
											key: "userinfo",
											data: JSON.stringify(userInfo)
										})
										//页面跳转，回到首页
										wx.reLaunch({
											url: "/pages/myinfo/myinfo"
										})
										uni.hideLoading();
									}
								})
							}
						})
					},
					fail: res => {
						uni.$showMsg("您取消了登录授权！")
					}
				})
			},
		}
	}
	
</script>

<style>
	@import url(../../static/css/login.css);
</style>
